package com.qmth.gkwb.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.qmth.gkwb.data.entity.BKKS;
import com.qmth.gkwb.data.entity.DictSignPoint;
import com.qmth.gkwb.data.entity.DictSubject;
import com.qmth.gkwb.data.entity.School;
import com.qmth.gkwb.data.repository.BKKSRepo;
import com.qmth.gkwb.data.repository.DictSignPointRepo;
import com.qmth.gkwb.data.repository.DictSubjectRepo;
import com.qmth.gkwb.data.repository.SchoolRepo;

@RestController
@RequestMapping("api/bkks")
public class BKKSApi {

@Autowired private BKKSRepo studentRepo;
	
	@Autowired private DictSignPointRepo signPointRepo;
	@Autowired private DictSubjectRepo subjectRepo;
	@Autowired private SchoolRepo schoolRepo;
	
	@RequestMapping(value="{id}",method=RequestMethod.GET)
	public BKKS getStudentById(@PathVariable String id){
		BKKS student = studentRepo.findOne(id);
		if(student != null){
			DictSubject ds = student.getSubjectId() == null?null:subjectRepo.findOne(student.getSubjectId());
			student.setSubject(ds);
			DictSignPoint sp = student.getSchoolId() == null?null:signPointRepo.findOne(student.getSchoolId());
			student.setSignPoint(sp);
			School school = student.getGradSchoolId() == null?null:schoolRepo.findOne(student.getSchoolId());
			student.setGradSchool(school);
		}
		return student;
	}
}
